package net.common.manager;

import java.util.ArrayList;
import java.util.List;

import com.naire.modul.function.service.FunctionSearchService;
import com.naire.modul.function.vo.FunctionVo;

public class MenuManager {

	private static List<FunctionVo> list = new ArrayList<FunctionVo>();

	/**
	 * 初始化系统菜单
	 * 
	 * @throws Exception
	 */
	public static void init() throws Exception {
		FunctionSearchService service = new FunctionSearchService();
		service.invoke();
		List<FunctionVo> voes = service.getList();
		for(FunctionVo vo : voes) {
			if(vo.getParent_num() == null) {
				list.add(vo);
				handler(service.getList(), vo.getFunction_num(), vo.getData());
			}
		}
		
	}

	private static void handler(List<FunctionVo> voes, String parent_num,
			List<FunctionVo> newVoes) throws Exception {
		for (FunctionVo vo : voes) {
			if(vo.getParent_num() != null && vo.getParent_num().equals(parent_num)) {
				newVoes.add(vo);
			}
		}
	}

	public static List<FunctionVo> getList() {
		return list;
	}

}
